
-----------------------------------------------------------------------------
-- 基本的编辑器
-- 1.文件浏览功能
-- 2.buffer切换
-- 3.状态栏
-- 4.文件搜索
-- 5.字符搜索和替换
-----------------------------------------------------------------------------


return {
     -- 主题
    'cormacrelf/vim-colors-github',
    'morhetz/gruvbox',
    'sainnhe/edge',
    "ful1e5/onedark.nvim",
    'folke/tokyonight.nvim',
    {
        'Mofiqul/vscode.nvim',
        config = function()
            local c = require('vscode.colors').get_colors()
            require('vscode').setup({
                -- Alternatively set style in setup
                 -- style = 'light',

                -- Enable transparent background
                transparent = true,

                -- Enable italic comment
                -- italic_comments = true,

                -- Disable nvim-tree background color
                -- disable_nvimtree_bg = true,

                -- Override colors (see ./lua/vscode/colors.lua)
                -- color_overrides = {
                --    vscLineNumber = '#FFFFFF',
                -- },

                -- Override highlight groups (see ./lua/vscode/theme.lua)
                group_overrides = {
                    -- this supports the same val table as vim.api.nvim_set_hl
                    -- use colors from this colorscheme by requiring vscode.colors!
                    Cursor = { fg=c.vscDarkBlue, bg=c.vscLightGreen, bold=true },
                }
            })
        end,
    },


    -- 快捷键提示
    -- https://github.com/folke/which-key.nvim
    {
         'folke/which-key.nvim',
        event = "VeryLazy",
        init = function()
            -- vim.o.timeout = true
            -- vim.o.timeoutlen = 100
        end,
        config = function()
            require "whichkey"
        end,
    },

    -- 启动界面
    -- https://github.com/glepnir/dashboard-nvim
    {
        'glepnir/dashboard-nvim',
        event = "VimEnter",
        config = function()
            local opts = {
                config = {
                    theme = 'hyper',
                    week_header = {
                        enable = true,
                    },
                    shortcut = {
                        { icon = '󰊳  ', desc='Update', group = '@property', action = 'Lazy update', key = 'u' }, {
                            icon = "  ",
                            desc = "新建文件",
                            key = "b",
                            action = ":ene <BAR> startinsert <CR>"
                        },
                        {
                            icon = "  ",
                            desc = '查找文件',
                            action = 'Telescope find_files',
                            key = 'f',
                        },
                        {
                            icon = ' ',
                            desc = '项目',
                            action = 'Telescope projects',
                            key = 'p',
                        },
                        {
                            icon = "󰏓  ",
                            desc = '最近文件',
                            action = 'Telescope oldfiles',
                            key = 'c',
                        },
                    },
                },
            }
            require("dashboard").setup(opts)
        end
    },



    -----------------------------------------------------------------------------
    -- 项目管理
    -- https://github.com/ahmedkhalf/project.nvim
    --
    -- 输出保存目录
    -- :lua print(require("project_nvim.utils.path").historyfile)
    --
    -- 我的文件在
    --  ~/.local/share/nvim/project_nvim/project_history
    -- <c-w> 切换工作目录
    -- <c-r> 最近文件
    -- <c-f> 查找工程文件
    -- <c-s> 在工程里搜索文本
    -- <c-d> 删除工程
    -----------------------------------------------------------------------------
    {
        "ahmedkhalf/project.nvim",
        dependencies = {
            'nvim-telescope/telescope.nvim',
        },
        config = function()
            local project = require("project_nvim")
            vim.g.nvim_tree_respect_buf_cwd = 1
            project.setup({
                -- Manual mode doesn't automatically change your root directory, so you have
                -- the option to manually do so using `:ProjectRoot` command.
                manual_mode = true,
                detection_methods = { "pattern" },
                patterns = {
                    "README.md",
                    "package.json",
                    ".sln",
                    ".git",
                    ".svn",
                },
            })
            local telescope = require("telescope")
            pcall(telescope.load_extension, "projects")
        end,
    },


    -----------------------------------------------------------------------------
    -- 文件浏览
    -- https://github.com/nvim-neo-tree/neo-tree.nvim
    -----------------------------------------------------------------------------
    {
        "nvim-neo-tree/neo-tree.nvim",
        branch = "v2.x",
        dependencies = {
            "nvim-lua/plenary.nvim",
            "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended
            "MunifTanjim/nui.nvim",
        },
        opts = {
            enable_git_status = true,
            enable_diagnostics = true,
            window = {
                position = "left",
                width = 36,
            },
            default_component_configs = {
                git_status = {
                    symbols = {
                        -- Change type
                        added     = "✚", -- or "✚", but this is redundant info if you use git_status_colors on the name
                        modified  = "", -- or "", but this is redundant info if you use git_status_colors on the name
                        deleted   = "✖",-- this can only be used in the git_status source
                        renamed   = "",-- this can only be used in the git_status source
                        -- Status type
                        untracked = "",
                        ignored   = "",
                        unstaged  = "",
                        staged    = "",
                        conflict  = "",
                    }
                },
            },
            filesystem = {
                filtered_items = {
                    visible = true,
                },
                window = {
                    mappings = {
                        -- ["/"] = 'fuzzy_finder',
                        ["/"] = '',
                    }
                },
            },

        },
    },


    -----------------------------------------------------------------------------
    -- ## bufferline
    -- https://github.com/akinsho/bufferline.nvim
    -----------------------------------------------------------------------------
    {
        "akinsho/bufferline.nvim",
        -- dependencies = {"kyazdani42/nvim-web-devicons", "moll/vim-bbye"},
        dependencies = {"nvim-tree/nvim-web-devicons", "moll/vim-bbye"},
        keys = require("keybinding").bufferline(),
        lazy = false,
        opts = {
            options = {
                -- 关闭 Tab 的命令
                close_command = "Bdelete! %d",
                right_mouse_command = "Bdelete! %d",
                -- 侧边栏配置
                -- 左侧让出 nvim-tree 的位置，显示文字 File Explorer
                offsets = {
                    {
                        filetype = "neo-tree",
                        -- filetype = "NvimTree",
                        text = "File Explorer",
                        highlight = "Directory",
                        text_align = "left",
                    },
                },
                diagnostics = "nvim_lsp",
                -- 可选，显示 LSP 报错图标
                ---@diagnostic disable-next-line: unused-local
                diagnostics_indicator = function(count, level, diagnostics_dict, context)
                    local s = " "
                    for e, n in pairs(diagnostics_dict) do
                        local sym = e == "error" and " " or (e == "warning" and " " or "")
                        s = s .. n .. sym
                    end
                    return s
                end,
            },
        },
    },


    -----------------------------------------------------------------------------
    -- ## 状态栏
    -- https://github.com/nvim-lualine/lualine.nvim
    -----------------------------------------------------------------------------
    {
        'nvim-lualine/lualine.nvim',
        dependencies = { 'nvim-tree/nvim-web-devicons'},
        opts = {
            options = {
                -- 指定皮肤
                -- https://github.com/nvim-lualine/lualine.nvim/blob/master/THEMES.md
                -- theme = "edge",
                -- 分割线
                component_separators = {
                    left = "|",
                    right = "|"
                },
                -- https://github.com/ryanoasis/powerline-extra-symbols
                section_separators = {
                    left = " ",
                    right = ""
                },
                globalstatus = true
            },
            extensions = {"nvim-tree"},
            sections = {
                lualine_c = {
                    "filename",
                    -- {
                    --     "lsp_progress",
                    --     spinner_symbols = {" ", " ", " ", " ", " ", " "}
                    -- },
                    -- {gps.get_location, cond = gps.is_available}
                },
                --   lualine_c = {
                -- 	{ gps.get_location, cond = gps.is_available },
                -- },
                --
                lualine_x = {
                    "filesize",
                    {
                        "fileformat",
                        -- symbols = {
                        --   unix = '', -- e712
                        --   dos = '', -- e70f
                        --   mac = '', -- e711
                        -- },
                        symbols = {
                            unix = "LF",
                            dos = "CRLF",
                            mac = "CR"
                        }
                    },
                    "encoding",
                    "filetype"
                }
            }

        },
    },


    -----------------------------------------------------------------------------
    -- ## 终端
    -----------------------------------------------------------------------------
    {
        "akinsho/toggleterm.nvim",
        lazy = false,
        config = function()
            ---@diagnostic disable: missing-parameter
            local toggleterm = require("toggleterm")
            toggleterm.setup({
                size = function(term)
                    if term.direction == "horizontal" then
                        return 15
                    elseif term.direction == "vertical" then
                        return vim.o.columns * 0.3
                    end
                end,
                start_in_insert = true,
            })
        end,
        keys = require("keybinding")["toggleterm"](),
    },


    -----------------------------------------------------------------------------
    -- ## 大纲预览
    -- https://github.com/simrat39/symbols-outline.nvim
    -----------------------------------------------------------------------------
    {
        'simrat39/symbols-outline.nvim',
        config = function()
            local opts = {
                highlight_hovered_item = true,
                show_guides = true,
                auto_preview = false,
                position = 'right',
                relative_width = true,
                width = 25,
                auto_close = false,
                show_numbers = false,
                show_relative_numbers = false,
                show_symbol_details = true,
                preview_bg_highlight = 'Pmenu',
                autofold_depth = 0,
                auto_unfold_hover = true,
                -- fold_markers = { '', '' },
                fold_markers = { '+', '-' },
                wrap = false,
                keymaps = { -- These keymaps can be a string or a table for multiple keys
                close = {"<Esc>", "q"},
                goto_location = "<Cr>",
                focus_location = "o",
                hover_symbol = "<C-space>",
                toggle_preview = "K",
                rename_symbol = "r",
                code_actions = "a",
                fold = "h",
                unfold = "l",
                fold_all = "W",
                unfold_all = "E",
                fold_reset = "R",
            },
            lsp_blacklist = {},
            symbol_blacklist = {
                -- 'File',
                -- 'Module',
                -- 'Namespace',
                -- 'Package',
                -- 'Class',
                -- 'Method',
                -- 'Property',
                -- 'Field',
                -- 'Constructor',
                -- 'Enum',
                -- 'Interface',
                -- 'Function',
                -- 'Variable',
                -- 'Constant',
                -- 'String',
                -- 'Number',
                -- 'Boolean',
                -- 'Array',
                -- 'Object',
                -- 'Key',
                -- 'Null',
                -- 'EnumMember',
                -- 'Struct',
                -- 'Event',
                -- 'Operator',
                -- 'TypeParameter',
                -- 'Component',
                -- 'Fragment',
            },
            symbols = {
                File = {icon = "", hl = "TSURI"},
                Module = {icon = "", hl = "TSNamespace"},
                Namespace = {icon = "", hl = "TSNamespace"},
                Package = {icon = "", hl = "TSNamespace"},
                Class = {icon = "𝓒", hl = "TSType"},
                Method = {icon = "ƒ", hl = "TSMethod"},
                Property = {icon = "", hl = "TSMethod"},
                Field = {icon = "", hl = "TSField"},
                Constructor = {icon = "", hl = "TSConstructor"},
                Enum = {icon = "ℰ", hl = "TSType"},
                Interface = {icon = "ﰮ", hl = "TSType"},
                Function = {icon = "", hl = "TSFunction"},
                Variable = {icon = "", hl = "TSConstant"},
                Constant = {icon = "", hl = "TSConstant"},
                String = {icon = "𝓐", hl = "TSString"},
                Number = {icon = "#", hl = "TSNumber"},
                Boolean = {icon = "⊨", hl = "TSBoolean"},
                Array = {icon = "", hl = "TSConstant"},
                Object = {icon = "⦿", hl = "TSType"},
                Key = {icon = "🔐", hl = "TSType"},
                Null = {icon = "NULL", hl = "TSType"},
                EnumMember = {icon = "", hl = "TSField"},
                Struct = {icon = "𝓢", hl = "TSType"},
                Event = {icon = "🗲", hl = "TSType"},
                Operator = {icon = "+", hl = "TSOperator"},
                TypeParameter = {icon = "𝙏", hl = "TSParameter"}
            }
        }
        require("symbols-outline").setup(opts)
        end,
    },

    -- ## bufexplorer
    'jlanzarotta/bufexplorer',


    -----------------------------------------------------------------------------
    -- 文件查找
    -- https://github.com/nvim-telescope/telescope.nvim
    -----------------------------------------------------------------------------
    {
        'nvim-telescope/telescope.nvim',
        dependencies = { 'nvim-lua/plenary.nvim' },
        config = function()
            local telescope = require("telescope")
            telescope.setup {
                defaults = {
                    -- 打开弹窗后进入的初始模式，默认为 insert，也可以是 normal
                    initial_mode = "insert",
                    -- vertical , center , cursor
                    layout_strategy = "horizontal",
                    -- 窗口内快捷键
                    mappings = require("keybinding").telescope_mappings,
                },
                pickers = {
                    find_files = {
                        -- theme = "dropdown", -- 可选参数： dropdown, cursor, ivy
                    },
                },
                extensions = {
                    ["ui-select"] = {
                        require("telescope.themes").get_dropdown({
                            -- even more opts
                        }),
                    },
                },
            }
            pcall(telescope.load_extension, "env")
            -- To get ui-select loaded and working with telescope, you need to call
            -- load_extension, somewhere after setup function:
            pcall(telescope.load_extension, "ui-select")
        end,
        keys = require("keybinding").telescope(),
    },

    -- https://github.com/LinArcX/telescope-env.nvim
    {"LinArcX/telescope-env.nvim"},

    -- https://github.com/nvim-telescope/telescope-ui-select.nvim
    {"nvim-telescope/telescope-ui-select.nvim"},


    -----------------------------------------------------------------------------
    -- 文本查找和替换
    -- https://github.com/nvim-pack/nvim-spectre
    -----------------------------------------------------------------------------
    {
        "windwp/nvim-spectre",
        keys = require("keybinding").spectre(),
        config = function()
            local spectre = require("spectre")
            --[[
            local plugin_maps = {
                open = "]o",
                open_visual = "]v",
                open_file_search = "]s",
                toggle_line = "]d",
                current_file = "]c",
                show_option_menu = "]m",
                run_replace = "]r",
                change_view_mode = "]e",
                select_entry = "<cr>"
                -- show_option_menu = "]o",
                --  run_replace = "]r",
                -- change_view_mode = "]v"
            }
            local opts = {
                mapping = {
                    -- 删除选中
                    ["toggle_line"] = {
                        map = plugin_maps.toggle_line,
                        cmd = "<cmd>lua require('spectre').toggle_line()<CR>",
                        desc = "toggle current item"
                    },
                    -- 前往文件
                    ["enter_file"] = {
                        map = plugin_maps.select_entry,
                        cmd = "<cmd>lua require('spectre.actions').select_entry()<CR>",
                        desc = "goto current file"
                    },
                    -- 查看菜单（忽略大小写、忽略隐藏文件）
                    ["show_option_menu"] = {
                        map = plugin_maps.show_option_menu,
                        cmd = "<cmd>lua require('spectre').show_options()<CR>",
                        desc = "show option"
                    },
                    -- 开始替换
                    ["run_replace"] = {
                        map =  plugin_maps.run_replace,
                        cmd = "<cmd>lua require('spectre.actions').run_replace()<CR>",
                        desc = "replace all"
                    },
                    -- 显示差异
                    ["change_view_mode"] = {
                        map = plugin_maps.change_view_mode,
                        cmd = "<cmd>lua require('spectre').change_view()<CR>",
                        desc = "change result view mode"
                    }
                }
            }
            --]]
            spectre.setup(opts)
        end,
    },


    -----------------------------------------------------------------------------
    -- ## 多光标操作
    -- https://github.com/mg979/vim-visual-multi
    -- https://github.com/mg979/vim-visual-multi/wiki/Quick-start
    -----------------------------------------------------------------------------
    {
        "mg979/vim-visual-multi",
        config = function()
            local vim_visual_multi_key =  {
                switch_mode = "<tab>",
                find_under = "<c-n>",
                skip_region = "<c-s>",
                remove_region = "<c-p>",
                cursor_up = "<c-k>",
                cursor_down = "<c-j>",
            }
            vim.g.VM_default_mappings = 0
            vim.g.VM_maps = {
                ["Switch Mode"] = vim_visual_multi_key.switch_mode,
                ["Find Under"] = vim_visual_multi_key.find_under,
                ["Skip Region"] = vim_visual_multi_key.skip_region,
                ["Remove Region"] = vim_visual_multi_key.remove_region,
                ["Select Cursor Down"] = vim_visual_multi_key.cursor_down,
                ["Select Cursor Up"]   =  vim_visual_multi_key.cursor_up
            }
        end,
    },


    -----------------------------------------------------------------------------
    -- ## 跳转插件 easy motion
    -- https://github.com/phaazon/hop.nvim
    -----------------------------------------------------------------------------
    {
        "phaazon/hop.nvim",
        branch = "v1", -- optional but strongly recommended
        keys = require("keybinding")["hop"](),
        config = function()
            require('hop').setup()
        end,
    },


    -----------------------------------------------------------------------------
    -- ## 添加 "" () {}
    -- https://github.com/ur4ltz/surround.nvim
    -- use "ur4ltz/surround.nvim"
    -- https://vimawesome.com/plugin/surround-vim
    -----------------------------------------------------------------------------
    {
        "ur4ltz/surround.nvim",
        config = function()
            local surround = require("surround")
            surround.setup {
                context_offset = 100,
                load_autogroups = false,
                --mappings_style = "sandwich",
                mappings_style = "surround",
                map_insert_mode = true,
                quotes = {"'", '"'},
                brackets = {"(", '{', '['},
                space_on_closing_char = false,
                pairs = {
                    nestable = {
                        ['('] = { "(", ")" },
                        ['['] = { "[", "]" },
                        ['{}'] = { "{", "}" },
                        ['<'] = { "<", ">" },
                    },
                    linear = {
                        ["'"] = { "'", "'" },
                        ["`"] = { "`", "`" },
                        ['"'] = { '"', '"' },
                    }
                },
                prefix = "s"
            }
        end,
    },


    -- https://github.com/nvim-lua/plenary.nvim
    "nvim-lua/plenary.nvim",


    --[[
    -- ## 精美弹窗
    -- https://github.com/rcarriga/nvim-notify
    {
        "rcarriga/nvim-notify",
    },
    --]]

    --[[
    -- ## 自动恢复光标位置
    {
        "ethanholz/nvim-lastplace",
    },
    --]]

    -- https://github.com/iamcco/markdown-preview.nvim
    -- {
        -- "iamcco/markdown-preview.nvim",
    -- },

}

